package org.example.controller;

import org.example.annotation.CheckPermission;
import org.example.pojo.domain.ArtifactMaintenance;
import org.example.result.Result;
import org.example.service.ArtifactMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/artifact-maintenance")
public class ArtifactMaintenanceController {

    @Autowired
    private ArtifactMaintenanceService artifactMaintenanceService;

    // 获取某文物的所有维护记录
    @CheckPermission({"curator"})
    @GetMapping("/artifact/{artifactId}")
    public Result getMaintenancesByArtifactId(@PathVariable Integer artifactId) {
        List<ArtifactMaintenance> maintenances = artifactMaintenanceService.getMaintenancesByArtifactId(artifactId);
        return Result.success("文物("+artifactId+")的所有维护记录",maintenances);
    }

    // 根据维护ID查询维护记录
    @CheckPermission({"curator"})
    @GetMapping("/{maintenanceId}")
    public Result getMaintenanceById(@PathVariable Integer maintenanceId) {
        ArtifactMaintenance maintenance = artifactMaintenanceService.getMaintenanceById(maintenanceId);
        return Result.success("维护ID("+maintenanceId+")查询维护记录",maintenance);
    }

    // 添加新维护记录
    @CheckPermission({"curator"})
    @PostMapping("/add")
    public Result addMaintenance(@RequestBody ArtifactMaintenance maintenance) {
        artifactMaintenanceService.addMaintenance(maintenance);
        return Result.success("维护记录添加成功！");
    }

    // 更新维护记录
    @CheckPermission({"curator"})
    @PutMapping("/update")
    public Result updateMaintenance(@RequestBody ArtifactMaintenance maintenance) {
        artifactMaintenanceService.updateMaintenance(maintenance);
        return Result.success("维护记录更新成功！");
    }

    // 删除维护记录
    @CheckPermission({"curator"})
    @DeleteMapping("/delete/{maintenanceId}")
    public Result deleteMaintenance(@PathVariable Integer maintenanceId) {
        artifactMaintenanceService.deleteMaintenance(maintenanceId);
        return Result.success("维护记录删除成功！");
    }
}
